home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / mail / pop.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  7KB  |  171 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from mail.smtp import SMTPEmailAccount
  5. from common import pref
  6. from util import dictadd, threaded, ResetTimer, get
  7. from logging import getLogger
  8. log = getLogger('popmail')
  9. info = log.info
  10. from mail.emailobj import DecodedEmail
  11. from mail.emailobj import Email
  12. import email
  13. import cPickle
  14. from zlib import decompress, compress
  15. from hashlib import sha1
  16. from util import CommandQueue, cmdqueue, callback_cmdqueue
  17.  
  18. class PopMail(SMTPEmailAccount):
  19.     protocol = 'pop'
  20.     default_timeout = 20
  21.     
  22.     def __init__(self, **options):
  23.         pprint = pprint
  24.         import pprint
  25.         pprint(options)
  26.         d = self.default
  27.         self.popserver = options.pop('popserver', '')
  28.         self.require_ssl = options.pop('require_ssl', d('require_ssl'))
  29.         self.popport = options.pop('popport', d('popport'))
  30.         self.uidlworks = None
  31.         self.topworks = True
  32.         self.cmdq = CommandQueue(start_hooks = [
  33.             self._connect], end_hooks = [
  34.             self._quit])
  35.         self.timeouttimer = ResetTimer(pref('pop.timeout', self.default_timeout), self.timeout_check)
  36.         SMTPEmailAccount.__init__(self, **options)
  37.  
  38.     can_has_preview = True
  39.     
  40.     def timeout_check(self):
  41.         log.info('Checking server connection for %r', self)
  42.         if self.state in (self.Statuses.OFFLINE, self.Statuses.ONLINE):
  43.             log.info('%s is not currently checking', self)
  44.             return True
  45.         
  46.         if get(self, 'conn', False):
  47.             
  48.             try:
  49.                 self.conn.noop()
  50.             self.on_error()
  51.             log.error("%s's server connection has failed", self)
  52.             return False
  53.  
  54.         else:
  55.             log.error('%s has no conn attribute', self)
  56.             self.on_error()
  57.             return False
  58.  
  59.     
  60.     def update(self):
  61.         SMTPEmailAccount.update(self)
  62.         log.info('starting timeout timer')
  63.         self.timeouttimer.start()
  64.         self.real_update(success = self.finish_update)
  65.  
  66.     
  67.     def finish_update(self, updates):
  68.         import time as time
  69.         if self.state == self.Statuses.OFFLINE:
  70.             log.error('finish_update exiting early, state is %s', self.state)
  71.             return None
  72.         
  73.         (updated_emails, updated_count) = updates
  74.         log.info('%s got %d new messages %s', self, updated_count, time.ctime(time.time()))
  75.         self._received_emails(updated_emails[:25], updated_count)
  76.         self.error_count = 0
  77.         log.info('stopping timeout timer')
  78.         self.timeouttimer.stop()
  79.  
  80.     
  81.     def real_update(self):
  82.         if self.state == self.Statuses.OFFLINE:
  83.             return None
  84.         
  85.         conn = self.conn
  86.         (num_emails, box_size) = conn.stat()
  87.         num_emails = int(num_emails)
  88.         emails = []
  89.         
  90.         def retr(mid):
  91.             if self.topworks:
  92.                 
  93.                 try:
  94.                     return conn.top(mid, 100)
  95.                 self.topworks = False
  96.  
  97.             
  98.             return conn.retr(mid)
  99.  
  100.         uidl = conn.uidl()
  101.         return (emails, num_emails)
  102.  
  103.     real_update = callback_cmdqueue()(real_update)
  104.     
  105.     def _connect(self):
  106.         if self.require_ssl:
  107.             pop = POP3_SSL
  108.             import poplib
  109.         else:
  110.             pop = POP3
  111.             import poplib
  112.         
  113.         try:
  114.             conn = pop(self.popserver, self.popport)
  115.         except Exception:
  116.             e = None
  117.             log.error('There was an error connecting: %s', e)
  118.             self.on_error()
  119.             raise 
  120.  
  121.         self.conn = conn
  122.         log.info(conn.user(self.name))
  123.         
  124.         try:
  125.             password = self._decryptedpw().encode('utf-8')
  126.             log.info(conn.pass_(password))
  127.         except Exception:
  128.             e = None
  129.             log.error('Bad password: %s', e)
  130.             self.error_txt = e.message
  131.             self.set_offline(self.Reasons.BAD_PASSWORD)
  132.             self.timer.stop()
  133.             raise 
  134.  
  135.         return conn
  136.  
  137.     
  138.     def _quit(self):
  139.         
  140.         try:
  141.             self.conn.quit()
  142.         except Exception:
  143.             e = None
  144.             log.error('Error when disconnecting: %s', str(e))
  145.             if self.state != self.Statuses.ONLINE:
  146.                 self.set_offline(self.Reasons.CONN_FAIL)
  147.             
  148.         except:
  149.             self.state != self.Statuses.ONLINE
  150.  
  151.  
  152.     
  153.     def delete(self, msg):
  154.         SMTPEmailAccount.delete(self, msg)
  155.         conn = self.conn
  156.  
  157.     delete = cmdqueue()(delete)
  158.     
  159.     def _get_options(self):
  160.         opts = SMTPEmailAccount._get_options(self)
  161.         opts.update((dict,)((lambda .0: for a in .0:
  162. (a, getattr(self, a)))('popserver popport require_ssl'.split())))
  163.         return opts
  164.  
  165.  
  166. if __name__ == '__main__':
  167.     from gui.toolbox import setuplogging
  168.     setuplogging()
  169.     PopMail('kevinwatters', 'linc4', popserver = 'pop.hotpop.com', popport = 110, require_ssl = False).update()
  170.  
  171.